Created by: Maribick Postanes
The code below imports the following Python libraries such as:
The code then reads the Excel file Historical Philippine Petroleum Prod (1979-2021).xlsx and stores the data in a pandas DataFrame set variable called df.
Next, the code creates a line plot using the px.line() function from the plotly.express library. The px.line() function takes a pandas DataFrame object as input and creates a line plot of the data. Then, the code customizes the plot by setting the title, labels, and line colors. It also shows the gridlines on the x-axis and y-axis.
To wrap up, the code shows the interactive plot using the fig.show() function.
# Import python libraries
import pandas as pd
import plotly.express as px
# Read the excel file
df = pd.read_excel('Historical Philippine Petroleum Prod (1979-2021).xlsx')
oilfield_color = ['Blue', 'Green', 'Red', 'darkturquoise', 'Purple', 'orange', 'brown', 'deeppink',
'royalblue', 'darkorange']
# Create a figure using Plotly Express
fig = px.line(df, x='Year - Oil', y='Oil Volume', color='Oilfield Name',
title='HISTORICAL PHILIPPINE PETROLEUM PRODUCTION, 1979-2021<br>As of December 31, 2021',
labels={'Year - Oil': 'YEAR OF PRODUCTION', 'Oil Volume': 'OIL VOLUME<br>(bbl)'},
line_group='Oilfield Name', color_discrete_sequence=oilfield_color)
# Customize the plot
fig.update_layout(showlegend=True, legend_title_text='Oilfield Name', title_x=0.5)
fig.update_xaxes(showgrid=True)
fig.update_yaxes(showgrid=True)
# Show the interactive plot
fig.show()
gas_field_color = ['Blue', 'Green', 'Red']
# Create a figure using Plotly Express
fig = px.line(df, x='Year - Gas', y='Gas Volume', color='Gas Field Name',
title='HISTORICAL PHILIPPINE PETROLEUM PRODUCTION, 1979-2021<br>As of December 31, 2021',
labels={'Year - Gas': 'YEAR OF PRODUCTION', 'Gas Volume': 'GAS VOLUME<br>(mmscf)'},
line_group='Gas Field Name', color_discrete_sequence=gas_field_color)
# Customize the plot
fig.update_layout(showlegend=True, legend_title_text='Gas Field Name', title_x=0.5)
fig.update_xaxes(showgrid=True)
fig.update_yaxes(showgrid=True)
# Adjust the plot size to width=1200 and height=750
fig.update_layout(width=950, height=600)
# Show the interactive plot
fig.show()
condensate_field_color = ['Orange']
# Create a figure using Plotly Express
fig = px.line(df, x='Year - Condensate', y='Condensate Volume', color='Condensate Field Name',
title='HISTORICAL PHILIPPINE PETROLEUM PRODUCTION, 1979-2021<br>As of December 31, 2021',
labels={'Year - Condensate': 'YEAR OF PRODUCTION', 'Condensate Volume': 'CONDENSATE VOLUME<br>(bbl)'},
line_group='Condensate Field Name', color_discrete_sequence=condensate_field_color)
# Customize the plot
fig.update_layout(showlegend=True, legend_title_text='Condensate Field Name', title_x=0.5)
fig.update_xaxes(showgrid=True)
fig.update_yaxes(showgrid=True)
# Adjust the plot size to width=1200 and height=750
fig.update_layout(width=950, height=600)
# Show the interactive plot
fig.show()